﻿using System;
using OccurrencesCore.Model;

namespace OccurrencesCore.Service
{
    public partial class ApplicationConfigurationService
    {
        public ApplicationConfiguration FindByKey(string key)
        {
            return _Repository.FindByKey(key);
        }

        public T GetValueByKeyOrDefault<T>(string key, T defaultValue)
        {
            ApplicationConfiguration appConfig = FindByKey(key);
            if (appConfig == null)
                return defaultValue;

            T valueRightType = (T)Convert.ChangeType(appConfig.Value, typeof(T));

            return valueRightType;
        }
    }
}
